#include<iostream>
#include<fstream>
#include"contacts.pb.h"
using namespace std;

void PrintContacts(contacts::Contacts&contacts)
{
    for(int i =0;i<contacts.contacts_size();i++)
    {
        cout << "-------------------联系人" <<i+1<<"-----------------"<<endl;
        const contacts::PeopleInfo& people = contacts.contacts(i); //
        cout << "联系人姓名：" << people.name() <<  endl;
        cout << "联系人年龄：" << people.age() <<  endl;
        for(int j =0;j<people.phone_size();j++)
        {
            const contacts::PeopleInfo_Phone& phone = people.phone(j);
            cout << "联系人电话"<<j+1<<":" <<phone.number();
            //联系人电话：13111111111111（MP）
            cout << "   (" << phone.PhoneType_Name(phone.type()) << ")" << endl;
        }
    }
}


int main()
{
    //读取本地已存在的通讯录文件
    contacts::Contacts contacts;
    // contacts2::Contacts contacts;
    //先读取本地已存在的联系人文件
    fstream input("constacts.bin",ios::in | ios::binary); 
 
    if(!contacts.ParseFromIstream(&input))  //
    {
        cerr << "parse error !" << endl;
        input.close();
        return -1;
    }

    //打印通讯录
    PrintContacts(contacts);
    return 0;
}